;;---------------------------------------------------------------------------
;; load library needed for ham2 evaluation paper diag plots 
;;
;; kai zhang, max planck institute for meteorology 
;;  
;;---------------------------------------------------------------------------

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "callvar.ncl"




;;------------------------------------------------------
  undef("sysopenfile")
;;------------------------------------------------------
  function sysopenfile(filename)
  begin

   if (isfilepresent(filename)) then
      fla = addfile(filename,"r")
   else
      fla = "nothing" 
   end if

   return(fla)
  end

;;------------------------------------------------------
;; gsn_csm_mine
;;------------------------------------------------------
undef("gsn_csm_mine")
function gsn_csm_mine(wks,vp,res,data_type)
begin

  if(data_type.eq."zonal") then
     plot = gsn_csm_pres_hgt(wks, vp, res)
  end if

  if(data_type.eq."surf") then
     plot = gsn_csm_contour_map_ce(wks, vp, res)
  end if

  return(plot)
end

;;------------------------------------------------------
;; get_varstr 
;;------------------------------------------------------
undef("get_varstr")
function get_varstr(varname)
begin

  if(varname.eq."msu") then
     varstr = "Sulfate"
  end if

  if(varname.eq."mbc") then
     varstr = "BC"
  end if

  if(varname.eq."mpm") then
     varstr = "POM"
  end if

  if(varname.eq."mdu") then
     varstr = "Dust"
  end if

  if(varname.eq."mss") then
     varstr = "Sea Salt"
  end if

  if(varname.eq."dms") then
     varstr = "DMS"
  end if

  if(varname.eq."so2") then
     varstr = "SO2"
  end if

  if(varname.eq."so4") then
     varstr = "SO4_gas"
     varstr = "SO4G"
  end if

  if(varname.eq."nus") then
     varstr = "NS"
  end if

  if(varname.eq."nks") then
     varstr = "KS"
  end if

  if(varname.eq."nas") then
     varstr = "AS"
  end if

  if(varname.eq."ncs") then
     varstr = "CS"
  end if

  if(varname.eq."nki") then
     varstr = "KI"
  end if

  if(varname.eq."nai") then
     varstr = "AI"
  end if

  if(varname.eq."nci") then
     varstr = "CI"
  end if

  if(varname.eq."TAU_2D") then
     varstr = "AOD"
  end if

  if(varname.eq."ABS_2D") then
     varstr = "AAOD"
  end if

  if(varname.eq."ANG") then
     varstr = "ANG"
  end if

  return(varstr)
end

;;------------------------------------------------------
;; get_varunit 
;;------------------------------------------------------
undef("get_varunit")
function get_varunit(varname,data_class)
begin

  if(varname.eq."msu" .or. \
     varname.eq."mbc" .or. \
     varname.eq."mpm" .or. \
     varname.eq."mso" .or. \
     varname.eq."mdu" .or. \
     varname.eq."mss"      ) then
     if(data_class.eq."mass") then
        unit = " (~F33~m~F~g)"
     end if
     if(data_class.eq."burden") then
        unit = " (mg m~S~-2~N~)"
     end if
  end if

  if(varname.eq."dms" .or. \ 
     varname.eq."so2"      ) then 
     if(data_class.eq."mass") then
        unit = " (pptv)"
     end if
     if(data_class.eq."burden") then
        unit = " (mg m~S~-2~N~)"
     end if
  end if

  if(varname.eq."so4") then 
     if(data_class.eq."mass") then
        unit = "" ;;"molecules cm~S~-3~N~"
     end if
     if(data_class.eq."burden") then
        unit = " (mg m~S~-2~N~)"
     end if
  end if

  if(varname.eq."nus" .or. \
     varname.eq."nks" .or. \
     varname.eq."nas" .or. \
     varname.eq."ncs" .or. \
     varname.eq."nki" .or. \
     varname.eq."nai" .or. \
     varname.eq."nci"      ) then
     if(data_class.eq."num") then
        unit = " (cm~S~-3~N~STP)"
     end if
  end if
  if(varname.eq."TAU_2D" .or. \
     varname.eq."ABS_2D" .or. \
     varname.eq."ANG"         ) then 
     unit = ""
  end if

  return(unit)
end


;;------------------------------------------------------
;; set_cnLevels
;;------------------------------------------------------
undef("set_cnLevels")
function set_cnLevels(data_class,data_type,varname,icase,ip,res)
begin

  if(data_type.eq."zonal") then
     cnLevels_msu      = (/0.001,0.002,0.005,0.01,0.02,0.05,0.1,0.2,0.5,0.8,1.0,2.0/)
     cnLevels_mbc      = (/0.001,0.002,0.005,0.008,0.01,0.02,0.05,0.08,0.1,0.15,0.2,0.25/)
     cnLevels_mpm      = (/0.001,0.002,0.005,0.01,0.02,0.05,0.1,0.2,0.5,0.8,1.0,2.0/)
     cnLevels_mdu      = (/0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,5.,10.,20.,30./)
     cnLevels_mss      = (/0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,5.,10.,20.,30./)
     cnLevels_dms      = (/0.1,0.2,0.5,1.,2.,5.,10.,20.,50.,100.,200.,500./)
     cnLevels_so2      = (/0.2,0.5,1.,2.,5.,10.,20.,50.,100.,200.,500.,1000./)
     cnLevels_so4      = (/5e-3,1e-2,2e-2,4e-2,6e-2,8e-2,1e-1,2e-1,3e-1,4e-1,6e-1,8e-1,1e0/)
     cnLevels_nus      = (/5e01,1e2,2e2,5e2,1e3,2e3,5e3,1e4,2e4,5e4,1e5,2e5,5e5/) 
     cnLevels_nks      = (/1e00,2e00,5e00,1e01,2e01,5e01,1e2,2e2,5e2,1e3,2e3,5e3,1e4/) 
     cnLevels_nas      = (/2e-1,5e-1,1e00,2e00,5e00,1e01,2e01,5e01,1e2,2e2,5e2,1e3,2e3/) 
     cnLevels_ncs      = (/1e-2,2e-2,5e-2,1e-1,2e-1,5e-1,1e0,2e0,5e0,1e1,2e1,5e1,1e2/) 
     cnLevels_nki      = (/1e-1,2e-1,5e-1,1e0,2e0,5e0,1e01,2e01,5e01,1e2,2e2,5e2,1e3/) 
     cnLevels_nai      = (/5e-3,1e-2,2e-2,5e-2,1e-1,2e-1,5e-1,1e0,2e0,5e0,1e01,2e01,5e1/) 
     cnLevels_nci      = (/5e-3,1e-2,2e-2,5e-2,1e-1,2e-1,5e-1,1e0,2e0,5e0,1e01,2e01,5e1/) 
     cnLevels_msu_diff = (/-0.5,-0.2,-0.1,-0.05,-0.02,-0.01,0.01,0.02,0.05,0.1,0.2,0.5/)
     cnLevels_mbc_diff = (/-0.05,-0.02,-0.01,-0.005,-0.002,-0.001,0.001,0.002,0.005,0.01,0.02,0.05/)
     cnLevels_mpm_diff = (/-0.5,-0.2,-0.1,-0.05,-0.02,-0.01,0.01,0.02,0.05,0.1,0.2,0.5/)
     cnLevels_mdu_diff = (/-5.,-1.,-0.5,-0.1,-0.05,-0.01,0.01,0.05,0.1,0.5,1.,5./)
     cnLevels_mss_diff = (/-5.,-1.,-0.5,-0.1,-0.05,-0.01,0.01,0.05,0.1,0.5,1.,5./)
     cnLevels_dms_diff = (/-100.,-50.,-20.,-10.,-5.,-2.,2.,5.,10.,20.,50.,100./)
     cnLevels_so2_diff = (/-100.,-50.,-20.,-10.,-5.,-2.,2.,5.,10.,20.,50.,100./)
     cnLevels_so4_diff = (/-5e-1,-2e-1,-1e-1,-5e-2,-2e-2,-1e-2,1e-2,2e-2,5e-2,1e-1,2e-1,5e-1/)
     cnLevels_nus_diff = (/-5e04,-2e4,-5e3,-2e3,-5e2,-2e02,2e02,5e2,2e3,5e3,2e4,5e4/)
     cnLevels_nks_diff = (/-5e03,-2e3,-5e2,-2e2,-5e1,-2e01,2e01,5e1,2e2,5e2,2e3,5e3/)
     cnLevels_nas_diff = (/-1e3,-5e2,-2e2,-1e2,-5e1,-2e1,2e1,5e1,1e2,2e2,5e2,1e3/)
     cnLevels_ncs_diff = (/-1e1,-5e0,-2e0,-1e0,-5e-1,-2e-1,2e-1,5e-1,1e0,2e0,5e0,1e1/)
     cnLevels_nki_diff = (/-2e2,-5e1,-2e1,-1e1,-5e0,-2e0,2e0,5e0,1e1,2e1,5e1,2e2/) 
     cnLevels_nai_diff = (/-5e0,-2e0,-1e0,-5e-1,-2e-1,-1e-1,1e-1,2e-1,5e-1,1e0,2e0,5e0/) 
     cnLevels_nci_diff = (/-5e0,-2e0,-1e0,-5e-1,-2e-1,-1e-1,1e-1,2e-1,5e-1,1e0,2e0,5e0/) 
  end if

  if(data_type.eq."surf") then
     cnLevels_msu      = (/0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,5.,10.,20.,40./)
     cnLevels_mbc      = (/0.005,0.01,0.02,0.05,0.1,0.15,0.2,0.25,0.5,1.,2.,5./)
     cnLevels_mpm      = (/0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,5.,10.,20.,40./)
     cnLevels_mdu      = (/0.05,0.1,0.2,0.5,1.,2.,5.,10.,20.,50.,100.,200./)
     cnLevels_mss      = (/0.05,0.1,0.2,0.5,1.,2.,5.,10.,20.,50.,100.,200./)
     cnLevels_dms      = (/0.5,1.,2.,5.,10.,20.,50.,100.,200.,500.,1000.,2000./)
     cnLevels_so2      = (/1.,2.,5.,10.,20.,50.,100.,200.,500.,1000.,2000.,4000./)
     cnLevels_so4      = (/5e-4,1e-3,2e-3,5e-3,1e-2,2e-2,5e-2,1e-1,2e-1,5e-1,1e0,2e0/)
     cnLevels_nus      = (/1e01,2e01,5e01,1e2,2e2,5e2,1e3,2e3,5e3,1e4,2e4,5e4,1e5/)
     cnLevels_nks      = (/2e00,5e00,1e01,2e01,5e01,1e2,2e2,5e2,1e3,2e3,5e3,1e4,2e4/)
     cnLevels_nas      = (/1e00,2e00,5e00,1e01,2e01,5e01,1e2,2e2,5e2,1e3,2e3,5e3,1e4/)
     cnLevels_ncs      = (/2e-2,5e-2,1e-1,2e-1,5e-1,1e0,2e0,5e0,1e1,2e1,5e1,1e2,2e2/)
     cnLevels_nki      = (/2e00,5e00,1e01,2e01,5e01,1e2,2e2,5e2,1e3,2e3,5e3,1e4,2e4/) 
     cnLevels_nai      = (/5e-2,1e-1,2e-1,5e-1,1e0,2e0,5e0,1e1,2e1,5e1,1e2,2e2,5e2/)
     cnLevels_nci      = (/5e-2,1e-1,2e-1,5e-1,1e0,2e0,5e0,1e1,2e1,5e1,1e2,2e2,5e2/)
     cnLevels_taod     = (/2e-3,5e-3,1e-2,2e-2,4e-2,6e-2,8e-2,1e-1,2e-1,4e-1,6e-1,8e-1/)
     cnLevels_aaod     = (/5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3,1e-2,2e-2,5e-2,1e-1,2e-1/) 
     cnLevels_tang     = (/2e-2,5e-2,1e-1,2e-1,4e-1,6e-1,8e-1,1e0,1.5e0,2e0,2.5e0,3e0/) 
     cnLevels_taod_obs = (/2e-3,5e-3,1e-2,2e-2,4e-2,6e-2,8e-2,1e-1,2e-1,4e-1,6e-1,8e-1/)
     cnLevels_msu_diff = (/-5.,-1.,-0.5,-0.2,-0.1,-0.05,0.05,0.1,0.2,0.5,1.,5./)
     cnLevels_mbc_diff = (/-0.2,-0.1,-0.05,-0.02,-0.01,-0.005,0.005,0.01,0.02,0.05,0.1,0.2/)
     cnLevels_mpm_diff = (/-5.,-1.,-0.5,-0.2,-0.1,-0.05,0.05,0.1,0.2,0.5,1.,5./)
     cnLevels_mdu_diff = (/-50.,-10.,-5.,-1.,-0.5,-0.1,0.1,0.5,1.,5.,10.,50./)
     cnLevels_mss_diff = (/-50.,-10.,-5.,-1.,-0.5,-0.1,0.1,0.5,1.,5.,10.,50./)
     cnLevels_dms_diff = (/-500.,-200.,-100.,-50.,-20.,-10.,10.,20.,50.,100.,200.,500./)
     cnLevels_so2_diff = (/-1000.,-500.,-200.,-100.,-50.,-20.,20.,50.,100.,200.,500.,1000./)
     cnLevels_so4_diff = (/-1e0,-5e-1,-2e-1,-1e-1,-5e-2,-2e-2,2e-2,5e-2,1e-1,2e-1,5e-1,1e0/)
     cnLevels_nus_diff = (/-2e4,-5e3,-2e3,-5e2,-2e2,-5e01,5e01,2e2,5e2,2e3,5e3,2e4/)
     cnLevels_nks_diff = (/-5e03,-2e3,-5e2,-2e2,-5e1,-2e01,2e01,5e1,2e2,5e2,2e3,5e3/)
     cnLevels_nas_diff = (/-5e3,-2e3,-5e2,-2e2,-5e01,-2e01,2e01,5e01,2e2,5e2,2e3,5e3/)
     cnLevels_ncs_diff = (/-5e1,-2e1,-5e0,-2e0,-5e-1,-2e-1,2e-1,5e-1,2e0,5e0,2e1,5e1/)
     cnLevels_nki_diff = (/-5e3,-2e3,-5e2,-2e2,-5e1,-2e1,2e1,5e1,2e2,5e2,2e3,5e3/)
     cnLevels_nai_diff = (/-1e2,-5e1,-2e1,-5e0,-2e0,-5e-1,5e-1,2e0,5e0,2e1,5e1,1e2/) 
     cnLevels_nci_diff = (/-1e2,-5e1,-2e1,-5e0,-2e0,-5e-1,5e-1,2e0,5e0,2e1,5e1,1e2/)
     cnLevels_taod_diff= (/-2e-1,-1e-1,-5e-2,-1e-2,-5e-3,-1e-3,1e-3,5e-3,1e-2,5e-2,1e-1,2e-1/)
     cnLevels_aaod_diff= (/-5e-2,-2e-2,-1e-2,-5e-3,-2e-3,-1e-3,1e-3,2e-3,5e-3,1e-2,2e-2,5e-2/) 
     cnLevels_tang_diff= (/-1e0,-5e-1,-2e-1,-1e-1,-5e-2,-1e-2,1e-2,5e-2,1e-1,2e-1,5e-1,1e0/) 

     cnLevels_msubd      = (/0.002,0.005,0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,5.,10./)
     cnLevels_msubd      = (/0.005,0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,5.,10.,20./)
     cnLevels_mbcbd      = (/0.005,0.01,0.02,0.05,0.1,0.15,0.2,0.25,0.5,1.,2.,5./)
     cnLevels_mpmbd      = (/0.005,0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,5.,10.,20./)
     cnLevels_mdubd      = (/0.1,0.2,0.5,1.,2.,5.,10.,20.,50.,100.,200.,500./)
     cnLevels_mssbd      = (/0.05,0.1,0.2,0.5,1.,2.,5.,10.,20.,50.,100.,200./)
     cnLevels_dmsbd      = (/0.001,0.002,0.005,0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,4./)
     cnLevels_so2bd      = (/0.005,0.01,0.02,0.05,0.1,0.2,0.5,1.,2.,5.,10.,20./)
     cnLevels_so4bd      = (/1e-5,2e-5,5e-5,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3,1e-2,2e-2/)
     cnLevels_msubd_diff = (/-2,-1.,-0.5,-0.2,-0.1,-0.05,0.05,0.1,0.2,0.5,1.,2./)
     cnLevels_msubd_diff = (/-5.,-2,-1.,-0.5,-0.2,-0.1,0.1,0.2,0.5,1.,2.,5./)
     cnLevels_mbcbd_diff = (/-1.,-0.5,-0.2,-0.1,-0.05,-0.02,0.02,0.05,0.1,0.2,0.5,1./)
     cnLevels_mpmbd_diff = (/-5.,-2.,-1.,-0.5,-0.2,-0.1,0.1,0.2,0.5,1.,2.,5./)
     cnLevels_mdubd_diff = (/-50.,-20.,-10.,-5.,-2.,-1.,1.,2.,5.,10.,20.,50./)
     cnLevels_mssbd_diff = (/-50.,-20.,-10.,-5.,-2.,-1.,1.,2.,5.,10.,20.,50./)
     cnLevels_dmsbd_diff = (/-0.2,-0.1,-0.05,-0.02,-0.01,-0.005,0.005,0.01,0.02,0.05,0.1,0.2/)
     cnLevels_so2bd_diff = (/-5.,-1.,-0.5,-0.2,-0.1,-0.05,0.05,0.1,0.2,0.5,1.,5./)
     cnLevels_so4bd_diff = (/-1e-2,-5e-3,-2e-3,-1e-3,-5e-4,-2e-4,-1e-4,1e-4,2e-4,5e-4,1e-3,2e-3,5e-3,1e-2/)
  end if

  if(isdefined("res@cnLevels")) then 
     delete(res@cnLevels)
  end if 

  if(varname.eq."dms") then 
     if(data_class.eq."mass") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_dms_diff
        else
           res@cnLevels = cnLevels_dms
        end if
     end if
     if(data_class.eq."burden") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_dmsbd_diff
        else
           res@cnLevels = cnLevels_dmsbd
        end if
     end if
  end if 

  if(varname.eq."so2") then
     if(data_class.eq."mass") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_so2_diff
        else
           res@cnLevels = cnLevels_so2
        end if
     end if
     if(data_class.eq."burden") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_so2bd_diff
        else
           res@cnLevels = cnLevels_so2bd
        end if
     end if
  end if

  if(varname.eq."so4") then
     if(data_class.eq."mass") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_so4_diff
        else
           res@cnLevels = cnLevels_so4
        end if
     end if
     if(data_class.eq."burden") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_so4bd_diff
        else
           res@cnLevels = cnLevels_so4bd
        end if
     end if
  end if

  if(varname.eq."msu") then
     if(data_class.eq."mass") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_msu_diff
        else
           res@cnLevels = cnLevels_msu
        end if
     end if
     if(data_class.eq."burden") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_msubd_diff
        else
           res@cnLevels = cnLevels_msubd
        end if
     end if
  end if

  if(varname.eq."mbc") then
     if(data_class.eq."mass") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_mbc_diff
        else
           res@cnLevels = cnLevels_mbc
        end if
     end if
     if(data_class.eq."burden") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_mbcbd_diff
        else
           res@cnLevels = cnLevels_mbcbd
        end if
     end if
  end if

  if(varname.eq."mpm") then
     if(data_class.eq."mass") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_mpm_diff
        else
           res@cnLevels = cnLevels_mpm
        end if
     end if
     if(data_class.eq."burden") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_mpmbd_diff
        else
           res@cnLevels = cnLevels_mpmbd
        end if
     end if
  end if

  if(varname.eq."mdu") then
     if(data_class.eq."mass") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_mdu_diff
        else
           res@cnLevels = cnLevels_mdu
        end if
     end if
     if(data_class.eq."burden") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_mdubd_diff
        else
           res@cnLevels = cnLevels_mdubd
        end if
     end if
  end if

  if(varname.eq."mss") then
     if(data_class.eq."mass") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_mss_diff
        else
           res@cnLevels = cnLevels_mss
        end if
     end if
     if(data_class.eq."burden") then
        if(icase.eq.2) then 
           res@cnLevels = cnLevels_mssbd_diff
        else
           res@cnLevels = cnLevels_mssbd
        end if
     end if
  end if

  if(varname.eq."nus") then
     if(icase.eq.2) then
        ;print(res@cnLevels) 
        res@cnLevels = cnLevels_nus_diff
     else
        res@cnLevels = cnLevels_nus
     end if
  end if

  if(varname.eq."nks") then
     if(icase.eq.2) then
        res@cnLevels = cnLevels_nks_diff
     else
        res@cnLevels = cnLevels_nks
     end if
  end if

  if(varname.eq."nas") then
     if(icase.eq.2) then
        res@cnLevels = cnLevels_nas_diff
     else
        res@cnLevels = cnLevels_nas
     end if
  end if

  if(varname.eq."ncs") then
     if(icase.eq.2) then
        res@cnLevels = cnLevels_ncs_diff
     else
        res@cnLevels = cnLevels_ncs
     end if
  end if

  if(varname.eq."nci") then
     if(icase.eq.2) then
        res@cnLevels = cnLevels_nci_diff
     else
        res@cnLevels = cnLevels_nci
     end if
  end if

  if(varname.eq."nki") then
     if(icase.eq.2) then
        res@cnLevels = cnLevels_nki_diff
     else
        res@cnLevels = cnLevels_nki
     end if
  end if

  if(varname.eq."nai") then
     if(icase.eq.2) then
        res@cnLevels = cnLevels_nai_diff
     else
        res@cnLevels = cnLevels_nai
     end if
  end if

  if(varname.eq."TAU_2D") then
     if(icase.ge.3) then
        res@cnLevels = cnLevels_taod_obs
     end if 
     if(icase.eq.2) then
        res@cnLevels = cnLevels_taod_diff
     end if 
     if(icase.le.1) then
        res@cnLevels = cnLevels_taod 
     end if
  end if

  if(varname.eq."ABS_2D") then
     if(icase.eq.2) then
        res@cnLevels = cnLevels_aaod_diff
     else
        res@cnLevels = cnLevels_aaod
     end if
  end if

  if(varname.eq."ANG") then
     if(icase.eq.2) then
        res@cnLevels = cnLevels_tang_diff
     else
        res@cnLevels = cnLevels_tang
     end if
  end if

  return(res@cnLevels)
end


;;------------------------------------------------------
;; make_plot
;;------------------------------------------------------
undef("make_plot")
function make_plot(wks,vp,res,data_class,data_type,varname,icase,case_str,ip)
begin

  sid = (/ "a)","b)","c)","d)","e)","f)","g)","h)","i)","j)", \
           "k)","l)","m)","n)","o)","p)","q)","r)","s)","t)"/)
  sx  = " "

  varstr = get_varstr(varname)

  if(data_type.eq."zonal" .and. icase.eq.0) then
    tiYAxisString      = "Pressure (hPa)~C~ "
  else
    tiYAxisString      = ""
  end if

  gsnCenterString = case_str(icase)  

  unit = get_varunit(varname,data_class)

  res@gsnLeftString        = sid(ip)+sx+varstr+unit
  res@gsnRightString       = "ANN"
  res@gsnCenterString      = gsnCenterString
  res@tiYAxisString        = tiYAxisString
  ;;if(varname.ne."so4") then 
  res@cnLevelSelectionMode = "ExplicitLevels"
  res@cnLevels             = set_cnLevels(data_class,data_type,varname,icase,ip,res)
  ;;else
  ;;res@cnLevelSelectionMode = "AutomaticLevels"
  ;;end if 
  res@lbLabelBarOn         = True
  plot = gsn_csm_mine(wks,vp,res,data_type)

  delete(res@cnLevels)

  return(plot)
end


